package com.test.pattern.interpret;

/**
 * @ClassName: Client
 * @description:
 * @author: Mr du
 * @create: 2024-04-01 21:47
 */
public class Client {

    public static void main(String[] args) {
        //定义环境类
        Context context = new Context();

        //定义变量类
        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        Variable d = new Variable("d");
        Variable e = new Variable("e");

        //将变量存储到环境中
        context.assign(a, 1);
        context.assign(b, 2);
        context.assign(c, 3);
        context.assign(d, 4);
        context.assign(e, 5);

        //获取抽象语法树
        AbstractExpression expression = new Minus(new Plus(new Plus(new Plus(a, b), c), d), e);
        System.out.println(expression + "= " + expression.interpret(context));
    }
}
